% Devin Koepl

classdef FootprintClass < handle
    
    properties (Constant)
        sig = @(x) 1 ./ (1 + exp(-x));
    end
    
    properties
        tlo;
        ttd;
        
        xtd;
        ytd;       
        xlo;
        ylo;      
        kx;
        ky;        
        bx;
        by;  
    end
    
    methods
        
        function obj = FootprintClass(tlo, ttd, xtd, ytd, xlo, ylo, kx, ky, bx, by)
            obj.tlo = tlo;
            obj.ttd = ttd;
            
            obj.xtd = xtd;
            obj.ytd = ytd;
            obj.xlo = xlo;
            obj.ylo = ylo;
            obj.kx  = kx;
            obj.ky  = ky;
            obj.bx  = bx;
            obj.by  = by;
        end
        
        function def = footprint_deflection(obj, t, x, xt, yt)
            if ( t >= obj.tlo )
                xt = obj.xtd - ( obj.xtd - obj.xlo ) * exp( -obj.kx / obj.bx * ( t - obj.tlo ) );
                yt = obj.ytd - ( obj.ytd - obj.ylo ) * exp( -obj.ky / obj.by * ( t - obj.tlo ) );           
            end

            rgnd = obj.ytd - yt;

            left_mask  = x <= xt;
            right_mask = x >  xt;

            left_def = max(rgnd .* exp(-50 * (obj.sig(obj.xtd - xt).^4 .* (x - xt).^2)), 0);
            right_def = max(rgnd .* exp(-50 * (obj.sig(xt - obj.xtd).^4 .* (x - xt).^2)), 0);

            def = (left_def .* left_mask + right_def .* right_mask) * (t > obj.ttd);           
        end
        
        function def = set_footprint_deflection(obj, x, xt, yt)            
          rgnd = obj.ytd - yt;
            
          left_mask  = x <= xt;
          right_mask = x >  xt;

          left_def = max(rgnd .* exp(-50 * (obj.sig(obj.xtd - xt).^4 .* (x - xt).^2)), 0);
          right_def = max(rgnd .* exp(-50 * (obj.sig(xt - obj.xtd).^4 .* (x - xt).^2)), 0);

          def = left_def .* left_mask + right_def .* right_mask;            
        end
        
    end
    
end